<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core">
	<f:view>

		<h:outputText value="Forma de Pagamento" /><br />
   		<h:selectOneMenu value="#{contasPagarManager.contasPagar.formaPagamento.id}" style="display:inline;">
   			<f:selectItem itemLabel="- Selecione -" />
   			<f:selectItems value="#{formaPagamentoManager.list}" var="forma" itemValue="#{forma.id}" itemLabel="#{forma.descricao}" />
   			<f:ajax execute="@this" render=":form_forma_pagamento:panel_pagamento" listener="#{contasPagarManager.selectFormaPagamento}" />
   		</h:selectOneMenu>
   		
   		<h:panelGroup id="panel_pagamento">
			<script type="text/javascript">
				$(function(){
					$(".valorPrincipal").maskMoney({thousands:'.', decimal:','});
				})
				$(function(){
					$(".juros").maskMoney({thousands:'.', decimal:','});
				})
				$(function(){
					$(".multa").maskMoney({thousands:'.', decimal:','});
				})
				$(function(){
					$(".desconto").maskMoney({thousands:'.', decimal:','});
				})
			</script>
   			<br />
   			<h:outputText value="Parcelar o Pagamento?" rendered="#{contasPagarManager.contasPagar.formaPagamento.podeGerarParcela}"/>
   			<h:selectBooleanCheckbox value="#{contasPagarManager.parcelamento}" rendered="#{contasPagarManager.contasPagar.formaPagamento.podeGerarParcela}">
   				<f:ajax event="click" render=":form_forma_pagamento" listener="#{contasPagarManager.changeParcelamento}"/>
   			</h:selectBooleanCheckbox>
   			
   			<br />
   			<h:outputText value="Quitar 1º Pagamento?" rendered="#{contasPagarManager.contasPagar.formaPagamento.darQuitacaoAutomatica}"/>
   			<h:selectBooleanCheckbox value="#{contasPagarManager.quitarPrimeiroPagamento}" 
   				rendered="#{contasPagarManager.contasPagar.formaPagamento.darQuitacaoAutomatica}" >
   				<f:ajax event="click" render=":form_forma_pagamento"/>
   			</h:selectBooleanCheckbox>
   			<br />
   			
			<table>
				<tr>
					<td style="font-weight: bold">
						<h:outputText value="Valor Principal" />
					</td>
					<td style="font-weight: bold">
						<h:outputText value="Juros" />
					</td>
					<td style="font-weight: bold">
						<h:outputText value="Multa" />
					</td>
					<td style="font-weight: bold" colspan="2">
						<h:outputText value="Desconto" />
					</td>
					<td style="font-weight: bold">
						<h:outputText value="Intervalo (DD)" />
					</td>
					<td style="font-weight: bold">
						<h:outputText value="Qtd Parcelas" />
					</td>
				</tr>
				<tr>
					<td style="vertical-align: bottom;">
		 				<h:inputText value="#{contasPagarManager.contasPagar.valorPrincipal}" style="width:100px;" styleClass="valorPrincipal">
		 					<f:convertNumber pattern="#,##0.00;(#,##0.00)" />
		 				</h:inputText>
		 			</td>
		 			<td style="vertical-align: bottom;">
		 				<h:inputText value="#{contasPagarManager.contasPagar.juros}" style="width:100px;" styleClass="juros">
		 					<f:convertNumber pattern="#,##0.00;(#,##0.00)" />
		 				</h:inputText>
		 			</td>
		 			<td style="vertical-align: bottom;">
		 				<h:inputText value="#{contasPagarManager.contasPagar.multa}" style="width:100px;" styleClass="multa">
		 					<f:convertNumber pattern="#,##0.00;(#,##0.00)" />
		 				</h:inputText>
		 			</td>
		 			<td style="vertical-align: bottom;">
		 				<h:selectOneRadio value="#{contasPagarManager.contasPagar.tipoDesconto}">
							<f:selectItems value="#{utilManager.listTipoDesconto}" />
						</h:selectOneRadio>
					</td>
					<td>
		 				<h:inputText value="#{contasPagarManager.contasPagar.desconto}" style="width:100px;" styleClass="desconto">
		 					<f:convertNumber pattern="#,##0.00;(#,##0.00)" />
		 				</h:inputText>
		 			</td>
		 			<td style="vertical-align: bottom;">
		 				<h:inputText value="#{contasPagarManager.intervalo}" style="width:100px;" disabled="#{!contasPagarManager.parcelamento}"/>
		 			</td>
		 			<td style="vertical-align: bottom;">
		 				<h:inputText value="#{contasPagarManager.quantidadeParcelas}" style="width:100px;" disabled="#{!contasPagarManager.parcelamento}"/>
		 				<p:commandButton title="Parcelar" icon="ui-icon-plusthick" style="height: 24px;" disabled="#{!contasPagarManager.parcelamento}"
						action="#{contasPagarManager.parcelar}" update=":form_forma_pagamento" process=":form_forma_pagamento"/>
		 			</td>
	 			</tr>
	 		</table>
	 		<br />
		 	<h:panelGroup rendered="#{contasPagarManager.parcelamento}">   	
		 		<p:dataTable value="#{contasPagarManager.listParcelas}" 
		 			var="conta"
		 			rows="5"
		 			paginator="true"
		 			>
		 			<p:column headerText="Parcela">
		 				<h:outputText value="#{conta.numeroParcela}"/>
		 			</p:column>
		 			<p:column headerText="Data de Pagamento">
		 				<h:outputText value="#{conta.dataPrevisaoPagamento}">
		 					<f:convertDateTime pattern="dd/MM/yyyy" />
		 				</h:outputText>
		 			</p:column>
		 			<p:column headerText="Valor">
		 				<h:outputText value="R$ " />
		 				<h:outputText value="#{conta.valorTotal}">
		 					<f:convertNumber pattern="#,##0.00;(#,##0.00)" />
		 				</h:outputText>
		 			</p:column>
		 		</p:dataTable>
		 	</h:panelGroup>
		 	
		 	<div style="text-align: right; width: 100%;">
		 		<p:commandButton value="Finalizar" action="#{contasPagarManager.fecharPedido}"
		 		update=":form"
		 		rendered="#{contasPagarManager.contasPagar.formaPagamento.id != null}"
		 		oncomplete="forma_pagamento_dlg.hide();"
		 		/>
		 	</div>

   		</h:panelGroup>
   		
    		
			   
	</f:view>
</html>